package dht.paxos;
import dht.HostAddress;
import dht.message.*;

public class OutstandingAcceptRequest implements OutstandingRequest {
    private final AcceptRequestMessage request;
    public OutstandingAcceptRequest(AcceptRequestMessage m) {
        this.request = m;
    }
    
    public HostAddress getAddress() {
        return request.getAddress();
    }
    
    public boolean isMatchingResponse(Message m) {
        if (!(m instanceof AcceptResponseMessage))
            return false;
        
        System.out.println("deciding if " + m + " is equal to " + request.toString());
        AcceptResponseMessage response = (AcceptResponseMessage)m;
        boolean result = request.getAddress().equals(response.getAddress())
            && request.getValue().equals(response.getValue())
            && request.getProposalNumber() == response.getProposalNumber();
        System.out.println("are we equal? " + result);
        return result;
    }
    
    public boolean isSameRequest(Message m) {
        if (!(m instanceof AcceptRequestMessage))
            return false;
        System.out.println("deciding if " + m + " i s equal to " + request.toString());
        AcceptRequestMessage otherRequest = (AcceptRequestMessage)m;
        boolean result =  otherRequest.getAddress().equals(request.getAddress())
            && otherRequest.getValue().equals(request.getValue())
            && otherRequest.getProposalNumber() == request.getProposalNumber();
        
        System.out.println("are we equal? " + result);
        return result;
    }
}
